package com.test.p14templatemethod.example01;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

public class StringDisplay extends AbstractDisplay{
    private String string ;

    private int width;

    public  StringDisplay(String string){
        this.string = string;
        try {
            this.width = string.getBytes("UTF-8").length;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void open() {
        printLine();
    }

    @Override
    public void print() {
        System.out.println("|"+string+"|");
    }

    @Override
    public void close() {
        printLine();
    }

    private void printLine(){
        System.out.println("+");
        for(int i=0;i<width;i++){
            System.out.println("-");
        }
        System.out.println("+");
    }
}
